<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>JavaScript 数组排序 </title>
</head>
<body>
<h2>以随机顺序排序数组</h2>
<p></p>


<p>请反复点击按钮，对数组进行随机排序。</p>

<button onclick="myFunction()">试一试</button>

<p id="demo"></p>

<script>
  var points = [40, 100, 1, 5, 25, 10];
  document.getElementById("demo").innerHTML = points;

  function myFunction() {
    points.sort(function(a, b){return 0.5 - Math.random()});
    document.getElementById("demo").innerHTML = points;
  }
</script>

</body>
</html>